﻿namespace Blaze.Editor.LuaExtensions
{
    using UnityEditor;
    using UnityEngine;

    internal class ScriptDropdownItem : AdvancedDropdownItem
    {
        private static class Styles
        {
            public static GUIStyle itemStyle = new GUIStyle("PR Label");

            static Styles()
            {
                itemStyle.alignment = TextAnchor.MiddleLeft;
                itemStyle.padding.left = 0;
                itemStyle.fixedHeight = 20;
                itemStyle.margin = new RectOffset(0, 0, 0, 0);
            }
        }

        public override GUIStyle lineStyle
        {
            get { return Styles.itemStyle; }
        }

        internal ScriptDropdownItem() : base("ROOT", -1)
        {
        }

        public ScriptDropdownItem(string path, int menuPath) : base(path, menuPath)
        {
        }

        public ScriptDropdownItem(string name, string menuPath, string command) : base(name, -1)
        {
            mMenuPath = menuPath;
            mLuaFilePath = command;
            m_Content = new GUIContent(name, mLuaIconTexture);
            m_ContentWhenSearching = new GUIContent(m_Content);
        }

        public override bool OnAction()
        {
            ChooseScriptWindow.mInstance.m_Target.LuaFilePath = mLuaFilePath;
            return true;
        }

        public override string ToString()
        {
            return mMenuPath;
        }

        private static readonly Texture2D mLuaIconTexture = BlazeEditorResources.Load<Texture2D>("icon_lua.png");
        private readonly string mLuaFilePath;
        private readonly string mMenuPath;
    }
}